const game = document.getElementsByClassName('game')[0];
const gameStyle = getComputedStyle(game);
const gameWidth = parseFloat(gameStyle.width);
class Pipe extends JuXing {
    constructor(height, top, speed, dom) {
        super(52, height, gameWidth, top, speed, 0, dom);
        this.isJiFeng = false;
    }
    onMove() {
        if (this.left <= -this.width) {
            this.dom.remove();
        }
    }
}

function getRandom(max, min) {
    return parseInt(Math.random() * (max - min) + min);
}

class PairPipe {
    constructor() {
        const fengXi = 150;
        const minHeight = 80;
        const maxHeight = landTop - minHeight - fengXi;
        const upHeight = getRandom(maxHeight, minHeight);
        const upDom = document.createElement('div');
        upDom.className = 'pipe up';
        this.upPipe = new Pipe(upHeight, 0, -100, upDom);

        const downHeight = landTop - upHeight - fengXi;
        const top = landTop - downHeight;
        const downDom = document.createElement('div');
        downDom.className = 'pipe down';
        this.downPipe = new Pipe(downHeight, top, -100, downDom);
        game.appendChild(upDom);
        game.appendChild(downDom);
    }

    move(time) {
        this.upPipe.move(time);
        this.downPipe.move(time);
    }
}

class ChuangJian {
    constructor() {
        this.pipes = [];
        this.timer = null;
    }
    start() {
        if (this.timer) {
            return;
        }
        this.timer = setInterval(() => {
            this.pipes.push(new PairPipe());
            for (let i = 0; i < this.pipes.length; i++) {
                if (this.pipes[i].upPipe.left < -this.pipes[i].upPipe.width) {
                    this.pipes.splice(i, 1);
                    i--;
                }
            }
        }, 1500);
    }
    stop() {
        clearInterval(this.timer);
        this.timer = null;
    }

    move(time) {
        for (let i = 0; i < this.pipes.length; i++) {
            this.pipes[i].move(time);
        }
    }
}

// var c = new ChuangJian();

// setInterval(() => {
//     c.move(16 / 1000);
// }, 16);